from fastapi import APIRouter, Form, HTTPException
from pydantic import ValidationError

from src.db.db_models import Stu_Info
from src.models import check_models
from src.sevices import BASE_INFO_SERVICES

base_info_router = APIRouter()


@base_info_router.post('/student', summary='新增学生信息')
async def post_new(student: check_models.StudentModel):
    return await BASE_INFO_SERVICES.add_stu(student)


# 查询所有学生
@base_info_router.get('/students', summary='查询全部学生信息')
async def get_students():
    stu = await Stu_Info.all()
    return stu


# 按条件查询学生
@base_info_router.get('/student/{}', summary='查询指定学生信息')
async def get_student(stu_id: int = None,
                      stu_class_name: str = None,
                      stu_name: str = None,
                      ):
    return await BASE_INFO_SERVICES.find_student(stu_id, stu_class_name, stu_name)


# 更新学生信息
@base_info_router.put('/student/{stu_id}', summary='更新学生信息')
async def update_student(stu_id: int, student: check_models.StudentModel):
    return await BASE_INFO_SERVICES.update_student(stu_id, student)
